package com.homework.dao;

import com.homework.config.ResourceConfig;
import com.homework.config.SpringConfig;
import com.homework.model.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/9/17 23:35
 */
@Repository
@Configuration
@Slf4j

public class UserDao {
    private SpringConfig springConfig;

    @Autowired
    private Connection conn ;
public UserDao() {}
    public int selectcount() throws SQLException {
ApplicationContext context = new ClassPathXmlApplicationContext("SpringConfig.class");
SpringConfig springConfig1 = (SpringConfig) context.getBean("springConfig");
conn=springConfig1.getConnection();
log.info("select count for all user in UserDao");
String sql="select count(*) from User";
ResultSet rs=conn.prepareStatement(sql).executeQuery();
rs.next();
        int count=rs.getInt(1);
return count;
}}
